home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / include / stdlib.h < prev    next >
C/C++ Source or Header  |  1990-11-29  |  6KB  |  205 lines

  1. /*
  2.  * stdlib.h --
  3.  *
  4.  *    Declares facilities exported by the "stdlib" portion of
  5.  *    the C library.
  6.  *
  7.  * Copyright 1988 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  *
  16.  * $Header: /sprite/src/lib/include/RCS/stdlib.h,v 1.18 90/11/27 11:24:17 ouster Exp $ SPRITE (Berkeley)
  17.  */
  18.  
  19. #ifndef _STDLIB
  20. #define _STDLIB
  21.  
  22. /* 
  23.  * sprite.h is needed for typedefs that are used in some function
  24.  * prototypes.  Unfortunately, some user programs define conflicting
  25.  * typedefs.  Because many programs probably include stdlib.h, we
  26.  * should give advance warning before forcing users to use the
  27.  * typedefs from sprite.h.  This must be done before we can turn on
  28.  * function prototypes for Sprite user programs.  (Or, change the 
  29.  * prototypes so that they don't use the Sprite typedefs.)
  30.  */
  31. #include <cfuncproto.h>
  32.  
  33. #ifdef KERNEL
  34. #include <sprite.h>
  35. #include <sys/types.h>
  36. #endif
  37.  
  38. #define EXIT_SUCCESS    0
  39. #define EXIT_FAILURE    1
  40.  
  41. #if defined(_HAS_PROTOTYPES) && !defined(_SIZE_T)
  42. #define _SIZE_T
  43. /* size_t is also defined in sys/types.h, stddef.h, and unistd.h. */
  44. typedef    int    size_t;
  45. #endif
  46.  
  47. /*
  48.  *----------------------------
  49.  * String conversion routines:
  50.  *----------------------------
  51.  */
  52.  
  53. _EXTERN double     atof _ARGS_((_CONST char *string));
  54. _EXTERN int     atoi _ARGS_((_CONST char *string));
  55. _EXTERN long int atol _ARGS_((_CONST char *string));
  56. _EXTERN double     strtod _ARGS_((_CONST char *string, char **endPtr));
  57. _EXTERN long int strtol _ARGS_((_CONST char *string, char **endPtr, int base));
  58. _EXTERN unsigned long int
  59.         strtoul _ARGS_((_CONST char *string, char **endPtr, int base));
  60.  
  61. /*
  62.  *------------------
  63.  * Memory allocator:
  64.  *------------------
  65.  */
  66.  
  67. /* 
  68.  * (Many of the "char *"s should be "Address".  See the above comments 
  69.  * about sprite.h.)
  70.  */
  71.  
  72. #ifdef KERNEL
  73.  
  74. _EXTERN Address    malloc _ARGS_((unsigned int bytesNeeded));
  75.  
  76. /*
  77.  * The mips compiler cannot handle some coercions on the left hand side.
  78.  */
  79. #ifndef mips
  80.  
  81. _EXTERN int    _free _ARGS_((Address blockPtr));
  82.  
  83. #ifdef lint
  84. #define        free(ptr) _free(ptr)
  85. #else
  86. #define        free(ptr) {_free(ptr); (ptr) = (Address) NIL; }
  87. #endif /* lint */
  88.  
  89. #else /* mips */
  90.  
  91. _EXTERN int    free _ARGS_((Address blockPtr));
  92.  
  93. #endif /* mips */
  94.  
  95. #else /* KERNEL */
  96.  
  97. _EXTERN _VoidPtr    malloc _ARGS_((unsigned int bytesNeeded));
  98. _EXTERN int    free _ARGS_((_VoidPtr blockPtr));
  99.  
  100. #endif /* KERNEL */
  101.  
  102. _EXTERN _VoidPtr    alloca _ARGS_((int size));
  103. _EXTERN _VoidPtr calloc _ARGS_((unsigned int numElems, unsigned int elemSize));
  104. _EXTERN _VoidPtr    realloc _ARGS_((_VoidPtr ptr, unsigned int newSize));
  105. _EXTERN void    Mem_Bin _ARGS_((int numBytes));
  106. _EXTERN char *    Mem_CallerPC();
  107. _EXTERN void    Mem_DumpTrace _ARGS_((int blockSize));
  108. _EXTERN void    Mem_PrintConfig _ARGS_((void));
  109. _EXTERN void    Mem_PrintInUse _ARGS_((void));
  110. _EXTERN void    Mem_PrintStats _ARGS_((void));
  111. _EXTERN void    Mem_PrintStatsInt _ARGS_((void));
  112. /* 
  113.  * The "proc" argument to Mem_SetPrintProc is a varargs function, 
  114.  * so we have delayed declaring the correct prototype for it.
  115.  */
  116. _EXTERN void    Mem_SetPrintProc _ARGS_((void (*proc)(), ClientData data));
  117. _EXTERN int    Mem_Size _ARGS_((Address blockPtr));
  118.  
  119. /*
  120.  * Structure used to set up memory allocation traces.
  121.  */
  122.  
  123. typedef struct {
  124.     int        size;    /* Size of block to trace. */
  125.     int        flags;    /* Flags defined below */
  126. } Mem_TraceInfo;
  127.  
  128. _EXTERN void    Mem_SetTraceSizes _ARGS_((int numSizes,
  129.                       Mem_TraceInfo *arrayPtr));
  130. /*
  131.  * Flags to determine what type of tracing to do.
  132.  *
  133.  *    MEM_PRINT_TRACE        A trace record will be printed each time that
  134.  *                an object of this size is alloc'd or freed.
  135.  *    MEM_STORE_TRACE        The number of blocks in use by each caller
  136.  *                up to a predefined maximum number of callers
  137.  *                is kept in a trace array .
  138.  *    MEM_DONT_USE_ORIG_SIZE    Don't use the original size for tracing, but use
  139.  *                the modified size used by malloc.
  140.  *    MEM_TRACE_NOT_INIT    The trace records stored for MEM_STORE_TRACE
  141.  *                have not been initialized yet.
  142.  */
  143.  
  144. #define    MEM_PRINT_TRACE        0x1
  145. #define    MEM_STORE_TRACE        0x2
  146. #define    MEM_DONT_USE_ORIG_SIZE    0x4
  147. #define    MEM_TRACE_NOT_INIT    0x8
  148.  
  149. extern int    mem_SmallMinNum;
  150. extern int    mem_LargeMinNum;
  151. extern int    mem_LargeMaxSize;
  152.  
  153. /*
  154.  * Statistics counters;  only incremented when tracing is enabled.
  155.  */
  156.  
  157. extern int    mem_NumAllocs;
  158. extern int    mem_NumFrees;
  159.  
  160. /*
  161.  *----------------------------------------------------------------
  162.  * Additional integer math routines, plus structures for returning
  163.  * results from them:
  164.  *----------------------------------------------------------------
  165.  */
  166.  
  167. typedef struct div_t {
  168.     int quot;
  169.     int rem;
  170. } div_t;
  171.  
  172. typedef struct {
  173.     long int quot;
  174.     long int rem;
  175. } ldiv_t;
  176.  
  177. _EXTERN int    abs _ARGS_((int j));
  178. _EXTERN div_t    div _ARGS_((int numer, int denom));
  179. _EXTERN long int labs _ARGS_((long j));
  180. _EXTERN ldiv_t    ldiv _ARGS_((long int numer, long int denom));
  181.  
  182. /*
  183.  *-----------------------------------
  184.  * Miscellaneous additional routines:
  185.  *-----------------------------------
  186.  */
  187.  
  188. _EXTERN void    abort _ARGS_((void));
  189. _EXTERN int    atexit _ARGS_((void (*func)(void)));
  190. _EXTERN _VoidPtr bsearch _ARGS_((_CONST _VoidPtr key, _CONST _VoidPtr base,
  191.         size_t n, size_t size,
  192.     int (*cmp)(_CONST _VoidPtr searchKey, _CONST _VoidPtr tableEntry)));
  193. _EXTERN int    exit _ARGS_((int status));
  194. _EXTERN char *    getenv _ARGS_((char *name));
  195. _EXTERN void    qsort _ARGS_((_VoidPtr base, int n, int size,
  196.       int (*compar)(_CONST _VoidPtr element1, _CONST _VoidPtr element2)));
  197. _EXTERN int    rand _ARGS_((void));
  198. _EXTERN long    random _ARGS_((void));
  199. _EXTERN void    setenv _ARGS_((_CONST char *name, _CONST char *value));
  200. _EXTERN int    srand _ARGS_((int seed));
  201. _EXTERN int    srandom _ARGS_((int seed));
  202. _EXTERN int    system _ARGS_((_CONST char *command));
  203.  
  204. #endif /* _STDLIB */
  205.